﻿@namespace SageKing.Studio.Pages.SageKingMessage.component

@inject SysDictTypeService selectService

<Form @ref="form"
      Model="@model" ValidateMode="@FormValidateMode.Rules"
      ValidateOnChange="true"
      LabelColSpan="6" WrapperColSpan="18">
    <Space Size=@("10") Wrap Align="SpaceAlign.Center">
        @GetSpaceItems(model.AttStrLst)
        @GetSpaceItems(model.AttsbyteLst)
        @GetSpaceItems(model.AttbyteLst)
        @GetSpaceItems(model.AttshortLst)
        @GetSpaceItems(model.AttushortLst)
        @GetSpaceItems(model.AttintLst)
        @GetSpaceItems(model.AttuintLst)
        @GetSpaceItems(model.AttlongLst)
        @GetSpaceItems(model.AttulongLst)
        @GetSpaceItems(model.AttfloatLst)
        @GetSpaceItems(model.AttdoubleLst)
    </Space>
</Form>

@code
{

    public RenderFragment GetSpaceItem<T>(KeyValueClass<string, T> item)
    {
        if (typeof(T) == CsharpTypeForICE.String)
        {
            return
    @<SpaceItem>
        @if (item.ColumnConfig.IsNullable)
    {

        <FormItem Label="@item.ColumnConfig.ColumnName" Style="width:388px;" LabelColSpan="8">
            <Input ShowCount MaxLength="64" Placeholder="@item.ColumnConfig.ColumnComment" @bind-Value="item.Value" />
        </FormItem>
    }else{

        <FormItem Label="@item.ColumnConfig.ColumnName" Style="width:388px;" LabelColSpan="8" Rules="[new FormValidationRule(){ Required = true }]" Required>
            <Input ShowCount MaxLength="64" Placeholder="@item.ColumnConfig.ColumnComment" @bind-Value="item.Value" />
        </FormItem>
    }
    </SpaceItem>;
        }

        return
    @<SpaceItem>
        @if (item.ColumnConfig.IsNullable)
    {
        <FormItem Label="@item.ColumnConfig.ColumnName" Style="width:388px;" LabelColSpan="8">
            <Tooltip Title="@typeof(T).ToString()">
                <AntDesign.InputNumber @bind-Value="item.Value" Width="125%" />
            </Tooltip>
        </FormItem>
    }else{
        <FormItem Label="@item.ColumnConfig.ColumnName" Style="width:388px;" LabelColSpan="8" Rules="[new FormValidationRule(){ Required = true, Type= FormFieldType.Number,  Min=1 }]" Required>
            <Tooltip Title="@typeof(T).ToString()">
                <AntDesign.InputNumber @bind-Value="item.Value" Width="125%" />
            </Tooltip>
        </FormItem>
    }
    </SpaceItem> ;
    }

    public RenderFragment GetSpaceItems<T>(List<KeyValueClass<string, T>> items)
    {
        if (!items.HasItem())
        {
            return@<span></span>;
        }
        var currLst = items.OrderBy(a => a.Key).ToList();
        return builder =>
        {
            @foreach (var item in currLst)
            {
                builder.OpenComponent(0, typeof(Space));
                builder.AddAttribute(1, "Align", SpaceAlign.Center);
                builder.AddAttribute(2, "ChildContent", GetSpaceItem(item));
                builder.CloseComponent();
            }
        };
    }
}

@code {

    #region IAddEdit
    [Parameter]
    public string Title { get; set; }

    [Parameter]
    public MessageModelForm model { get; set; }

    public AntDesign.Form<MessageModelForm> form { get; set; }
    #endregion

    public bool FormCheck()
    {
        return form.Validate();
    }
    //select data
    SysDictType SelectType;

    protected override async Task OnInitializedAsync()
    {
        // SelectType = await selectService.GetDetailCache(SysDictTypeConst.code_message_type);
    }

}